<?php
/**
 * Created by PhpStorm.
 * User: 尧
 * Date: 11/20/2016
 * Time: 8:26 PM
 */
use yii\helpers\Url;
?>
<?php
    $url = Url::to(['api/ajax']);
    $this->register(<<<JS
        $('#button-ajax').click(function (){
            var url = '$url';
            var data = {};
             $.get(url, data, function() {
               alert(response);
               console.log(response);
             },'json');
        });
JS
    );
?>

<button id="button-ajax">ajax请求按钮</button>
